package service

import (
	"fly/models"
	"github.com/beego/beego/v2/client/orm"
	"github.com/duke-git/lancet/v2/condition"
	"net/url"
)

type SysLogAdminService struct {
	BaseService
}

// GetPaginateData 分页获取
func (c *SysLogAdminService) GetPaginateData(params url.Values) ([]*models.SysLogAdmin, Pagination) {
	//搜索、查询字段赋值
	c.WhereField = append(c.WhereField, new(models.SysLogAdmin).WhereField()...)

	var list []*models.SysLogAdmin
	o := orm.NewOrm().QueryTable(new(models.SysLogAdmin))
	_, err := c.PaginateAndScopeWhere(o, params, func(cond *orm.Condition) *orm.Condition {
		cond = condition.TernaryOperator(params.Has("operName"), cond.And("oper_name", params.Get("operName")), cond)
		return cond
	}).All(&list)
	if err != nil {
		return nil, c.Pagination
	}
	return list, c.Pagination
}
